const app = getApp();

Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		"cardinfo":{type:Object},
	},

	/**
	 * 组件的初始数据
	 */
	data: {},

	/**
	 * 组件的方法列表
	 */
	methods: {
       cancel:function(){
		   this.triggerEvent('popup',{popup:false});
	   },

	   opencard:function (e) {
		    app.func.getPromise('/card/opencard/' + this.data.cardinfo.id)
				.then(([code,res])=>{
					if(code == 200){
						this.triggerEvent('popup',{popup:false});
						app.func.toastPromise('开卡成功','success', 2000)
							.then(()=>{
								this.triggerEvent('refresh',{});
							})
					}
					else if(code == 6001){
						app.func.toastPromise(res.message,'none',1500)
							.then(()=>{
								wx.navigateTo({
									url:'/pages/about/balance/chargelist/addcharge/addcharge?price=2000'
								})
							})
					}
					else{
						app.func.toastPromise(res.message)
					}
				})
	   }
	}
})


